package models;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.OrderBy;
import javax.persistence.OrderColumn;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import play.data.validation.Required;
import play.db.jpa.Model;

@Entity
public class BookCopy extends Model {

	@Required
	@ManyToOne
	public Book book;
	
	@Required
	@ManyToOne
	public Library library;
	
	/**
	 * book number - optional 
	 */
	public String number;
	
	/**
	 * if book is taken
	 */
	boolean taken;
	
	@OneToOne
	public BookHistory lastLoan;
	
	
	/**
	 * loan history, lastLoad is on the list.
	 */
	@OneToMany(mappedBy="bookCopy")
	@OrderBy("takenDate")
	public List<BookHistory> history = new ArrayList<BookHistory>();
	
	
	@Override
	public String toString() {
		return "" + book + "[" + library + "]";
	}

}
